/**
 * 
 */
package org.jenkon.commons.io.comparator;

import java.io.File;
import java.util.Comparator;

import org.jenkon.commons.io.utils.FileUtils;

/**
 * <p>
 * {@link Comparator} to compare the size of two {@link File} objects.
 * </p>
 * 
 * <p>
 * If the size of left {@link File} it creater as the size of right {@link File}, then
 * <code>1</code>. If the size of left {@link File} it smaller as the size of right {@link File},
 * then <code>-1</code>. If the size of left {@link File} and right {@link File} it equals, then
 * <code>0</code>.
 * </p>
 * 
 * <p>
 * <b>Example:</b>
 * </p>
 * 
 * <pre>
 * new SizeFileComparator()
 * 	.compare(file1, file2);
 * </pre>
 * 
 * @author Jens Konopka
 * @see Comparator#compare(Object, Object)
 * 
 */
public class SizeFileComparator implements Comparator<File> {

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(final File left, final File right) {
		final long result = FileUtils.sizeOf(left) - FileUtils.sizeOf(right);
		if (result < 0) {
			return -1;
		} else if (result > 0) {
			return 1;
		}
		return 0;
	}

}
